package demo4;

public abstract class MyTask implements Runnable ,Comparable<MyTask>{
    private long time;

    @Override
    public int compareTo(MyTask o) {
        if(this.getTime()-o.getTime()>0) return 1;
        else if(this.getTime()-o.getTime()<0) return -1;
        else return 0;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long delay) {
        if(delay<0) throw new IllegalArgumentException("定时不能小于0");
        this.time = System.currentTimeMillis()+delay;
    }
}
